<head>
    <link href="${ctx}/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <link href="${ctx}/font-awesome/3.0.0/css/font-awesome.min.css" rel="stylesheet">
    <link href="${ctx}/css/index.css" rel="stylesheet">
    <link href="${ctx}/bootstrap-table/1.12.0/bootstrap-table.min.css" rel="stylesheet">
    <script src="${ctx}/jquery/2.1.4/jquery.min.js"></script>
    <script src="${ctx}/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="${ctx}/bootstrap-table/1.12.0/bootstrap-table.min.js"></script>
    <script src="${ctx}/bootstrap-table/1.12.0/locale/bootstrap-table-zh-CN.min.js"></script>
    <script src="${ctx}/bootstrap-table/1.12.0/extensions/export/bootstrap-table-export.min.js"></script>
    <script src="${ctx}/js/extends.js"></script>
    <script src="${ctx}/layui/layui.all.js"></script>
    <script src="${ctx}/js/util.js"></script>
    <link href="${ctx}/layui/css/layui.css" rel="stylesheet">
    <style>
        .btn {
            font-size: 12px;
        }

        .lay-box {
            padding: 10px;
        }
    </style>
</head>
<body>
<title>首页模块控制</title>
<div class="lay-box">
    <button class="layui-btn" onclick="search()">
        <i class="layui-icon">&#xe669;</i> 查询
    </button>
    <input type="text" id="title" style="height: 38px">
    <div>
        <div style="width: 250px;">
            <select id="type" lay-verify="" onchange="search()">
                <option value="tb_common">通用任务</option>
                <option value="tb_soso">搜搜任务</option>
            </select>
        </div>
    </div>
    <table class="table table-border table-bordered table-hover table-bg table-sort" id="layTable"
           lay-filter="tableFilter">

    </table>
</div>


</body>
<style>

</style>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>


<!--请在下方写此页面业务相关的脚本-->
<script type="text/html" id="switchTpl">
    <!-- 这里的 checked 的状态只是演示 -->
    <input type="checkbox" name="sex" value="{{d.id}}" lay-skin="switch" lay-text="启用|禁用" lay-filter="sexDemo" {{
           d.hasDeleted== '0' ? 'checked' : '' }}>

</script>
<script type="text/javascript">
    var startDate = "";
    var endDate = "";
    var searchKey = "";
    var marketId = "";
    var tableIns;
    var ids = "";
    var form;
    var table = "tb_common";

    layui.use('table', function () {
        tableIns = layui.table,
            form = layui.form;
        tableIns.render({
            elem: '#layTable'
            ,
            url: '/common/task/list'
            ,
            method: 'POST'
            ,
            where: {
                // table: table,
                // query: {'status': 'On', 'id': ''},
                // time: {'start': startDate, 'end': endDate},
                // key: {'title': searchKey},
                // orderBy: 'order by create_time desc'
                status:'On',
                title: searchKey
            }
            ,
            id: 'dataTableId'
            ,
            cols: [[
                {type: 'checkbox', field: 'id'}

                , {
                    field: 'title',
                    title: '任务名称',
                    width: 150,
                    align: 'center',
                    sort: true
                }
                , {
                    field: 'task_id',
                    title: '任务id',
                    width: 150,
                    align: 'center',
                    sort: true
                }, {
                    field: 'gmt_created', title: '创建时间', templet: function (data) {
                        return dateFormat(data.create_time);
                    }, align: 'center', width: 200, sort: true
                }


            ]]
            ,
            page: true
        });


//监听行单击事件
        tableIns.on('row(tableFilter)', function (obj) {

//例子1
            var money = '+' + obj.data.worth / 100 + '元'
            layer.prompt({
                formType: 2,
                value: money,
                title: '请输入副标题',
                area: ['200px', '50px'] //自定义文本域宽高
            }, function (value, index, elem) {

                addrecord(obj.data, value);
                layer.close(index);
            });
        });
    });


    function search() {
        searchKey = $("#title").val();
        marketId = $(".select").eq(0).val();
        table = $("#type").val();
        tableIns.reload('dataTableId', {
            where: {
                // table: table,
                // query: {'name': ''},
                // time: {'start': startDate, 'end': endDate},
                // key: {'title': searchKey}
                status:'On',
                title:searchKey
            }
            , page: {curr: 1}
        });
    }


    function showmsg(msg) {
        layer.msg(msg)
    }


    function addrecord(data, msg) {

        $.ajax({
            url: "/sys/taskearn/record",    //请求的url地址
            dataType: "json",   //返回格式为json
            async: true,//请求是否异步，默认为异步，这也是ajax重要特性
            data: {taskId: data.task_id, icon: data.icon, title: data.title, type: table, msg: msg},    //参数值,键值对
            type: "post",   //请求方式
            beforeSend: function () {
                //请求前的处理
            },
            success: function (req) {
                //请求成功时处理
                if (req.success) {
                    parent.showmsg(req.message);
                    parent.search();
                    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                    parent.layer.close(index); //再执行关闭
                } else {
                    layer.msg(req.message)
                }
            },
            complete: function () {
                //请求完成的处理
            },
            error: function () {
                //请求出错处理
                layer.msg("请重试！若在失败请联系管理员")
            }
        });
    }


</script>
<!--/请在上方写此页面业务相关的脚本-->
